<?php
namespace app\model\crm;

use think\Model;

class Followup extends Model
{
    // 设置表名
    protected $name = 'crm_followup';
    
    // 自动写入时间戳
    protected $autoWriteTimestamp = true;
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';
    
    // 定义字段类型
    protected $type = [
        'followup_type' => 'integer',
        'followup_time' => 'datetime',
        'followup_result' => 'integer',
        'next_followup_time' => 'datetime'
    ];
    
    // 关联客户
    public function customer()
    {
        return $this->belongsTo(Customer::class, 'customer_id');
    }
    
    // 获取跟进方式标签
    public function getFollowupTypeTextAttr($value, $data)
    {
        $types = [
            1 => '电话联系',
            2 => '微信沟通',
            3 => '邮件联系',
            4 => '上门拜访',
            5 => '会议沟通'
        ];
        return $types[$data['followup_type']] ?? '未知';
    }
}